package my_cplex;

import java.util.Random;

public class my_cplex {
    public double[][] create_dataset(int rows,int cols,boolean print,int magnify){//最后一个参数是放大值，扩大随机数范围
        //创建Random对象
        Random rand = new Random();
        int decimalPlaces = 2;//限制小数点后三位

        double[][] randomArray = new double[rows][cols];
        double scale = Math.pow(10,decimalPlaces);

        for(int i=0;i<rows;i++){
            for(int j=0;j<cols;j++){
                double rawValue = rand.nextDouble()*magnify;
                randomArray[i][j] = Math.round(rawValue*scale)/scale;
            }
        }

        //是否打印生成的数组
        if(print){
            for(int i=0;i<rows;i++){
                for(int j=0;j<cols;j++){
                    System.out.print(randomArray[i][j]+" ");
                }
                System.out.println();
            }
        }
        return randomArray;
    }
}
